<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model :model="model" :form="form" :rules="rules" ref="form" layout="vertical">
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="日期" prop="time">
              <!--              <a-input placeholder="请输入" v-model="model.time" style="width: 100%" />-->
              <a-date-picker
                v-model:value="time"
                placeholder="选择日期"
                style="width:100%"
                :allowClear="false"
                @change="changeTime"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="车间" prop="workshop">
              <j-dict-select-tag placeholder="请选择车间" v-model="model.workshop" dictCode="workshop" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="班次" prop="shift">
              <j-dict-select-tag placeholder="请选择班次" v-model="model.shift" dictCode="shift" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="上班时间" prop="workHours">
              <a-input-number placeholder="请输入" v-model="model.workHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="机台时间" prop="machineHours">
              <a-input-number placeholder="请输入" v-model="model.machineHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机号" prop="deviceNo">
              <a-input placeholder="请输入" v-model="model.deviceNo" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台（单个）" prop="deviceId">
              <a-input placeholder="请输入" v-model="model.deviceId" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="工号" prop="workNo">
              <a-input placeholder="请输入" v-model="model.workNo" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="姓名" prop="realname">
              <a-input placeholder="请输入" v-model="model.realname" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="品种" prop="productType">
              <j-dict-select-tag
                v-model="model.productType"
                placeholder="请输入品种"
                dictCode="crm_product_type_rove,product_type,id"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台系数" prop="machineCoefficient">
              <a-input placeholder="请输入" v-model="model.machineCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="品种系数" prop="productTypeCoefficient">
              <a-input placeholder="请输入" v-model="model.productTypeCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="单价系数" prop="unitPriceCoefficient">
              <a-input placeholder="请输入" v-model="model.unitPriceCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="综合系数" prop="comprehensiveCoefficient">
              <a-input placeholder="请输入" v-model="model.comprehensiveCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="锭数" prop="ingots">
              <a-input placeholder="请输入" v-model="model.ingots" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="定量" prop="quantify">
              <a-input placeholder="请输入" v-model="model.quantify" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="线速度" prop="linearVelocity">
              <a-input placeholder="请输入" v-model="model.linearVelocity" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="粗纱定长(m)" prop="fixedLengthRove">
              <a-input placeholder="请输入" v-model="model.fixedLengthRove" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="8小时定额长度" prop="fixedLengthEightHours">
              <a-input placeholder="请输入" v-model="model.fixedLengthEightHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="台数" prop="machinesNum">
              <a-input placeholder="请输入" v-model="model.machinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="看台数(8小时)" prop="machinesNumEightHours">
              <a-input placeholder="请输入" v-model="model.machinesNumEightHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="定额看台（台）" prop="fixedMachinesNum">
              <a-input placeholder="请输入" v-model="model.fixedMachinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="总看台率%" prop="totalMachinesRate">
              <a-input placeholder="请输入" v-model="model.totalMachinesRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="接班长度" prop="takeoverLength">
              <a-input placeholder="请输入" v-model="model.takeoverLength" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="交班长度" prop="handoverLength">
              <a-input placeholder="请输入" v-model="model.handoverLength" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="实际长度" prop="realityLength">
              <a-input placeholder="请输入" v-model="model.realityLength" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="产量（KG）" prop="weight">
              <a-input placeholder="请输入" v-model="model.weight" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱数(次/台)" prop="doffNum">
              <a-input placeholder="请输入" v-model="model.doffNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="换桶数（桶/台）" prop="bucketChangeNum">
              <a-input placeholder="请输入" v-model="model.bucketChangeNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱单价（元/次）" prop="doffUnitPrice">
              <a-input placeholder="请输入" v-model="model.doffUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="换桶单价（元/桶）" prop="bucketChangeUnitPrice">
              <a-input placeholder="请输入" v-model="model.bucketChangeUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="清洁产量单价（百米/元）" prop="cleanProductionUnitPrice">
              <a-input placeholder="请输入" v-model="model.cleanProductionUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="落纱工资（元）" prop="doffWages">
              <a-input placeholder="请输入" v-model="model.doffWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="换桶工资(元)" prop="bucketChangeWages">
              <a-input placeholder="请输入" v-model="model.bucketChangeWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="清洁产量工资（元）" prop="cleanProductionWages">
              <a-input placeholder="请输入" v-model="model.cleanProductionWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="系数补扣" prop="coefficientDeduction">
              <a-input placeholder="请输入" v-model="model.coefficientDeduction" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="其它补贴" prop="otherSubsidies">
              <a-input placeholder="请输入" v-model="model.otherSubsidies" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="合计工资" prop="totalWages">
              <a-input placeholder="请输入" v-model="model.totalWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="完成率%" prop="completionRate">
              <a-input placeholder="请输入" v-model="model.completionRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台保养" prop="machinesMaintenance">
              <a-input placeholder="请输入" v-model="model.machinesMaintenance" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="备注" prop="remark">
              <a-input placeholder="请输入" v-model="model.remark" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="看台审核" prop="platformReview">
              <a-input placeholder="请输入" v-model="model.platformReview" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="单台看台率" prop="singlePlatformViewingRate">
              <a-input placeholder="请输入" v-model="model.singlePlatformViewingRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="台日时（24小时）" prop="platformDayHours">
              <a-input placeholder="请输入" v-model="model.platformDayHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="品种类别" prop="productCategory">
              <a-input placeholder="请输入" v-model="model.productCategory" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="公司" prop="company">
              <a-input placeholder="请输入" v-model="model.company" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="开始时间" prop="startTime">
              <a-input placeholder="请输入" v-model="model.startTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="结束时间" prop="endTime">
              <a-input placeholder="请输入" v-model="model.endTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <!--        <a-row class="form-row" :gutter="16">-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="工号转换" prop="workIdConversion">-->
        <!--              <a-input placeholder="请输入" v-model="model.workIdConversion" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="原单价" prop="originalPrice">-->
        <!--              <a-input placeholder="请输入" v-model="model.originalPrice" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="原工资" prop="originalWages">-->
        <!--              <a-input placeholder="请输入" v-model="model.originalWages" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="现-原" prop="originalNow">-->
        <!--              <a-input placeholder="请输入" v-model="model.originalNow" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--        </a-row>-->
        <!--        <a-row class="form-row" :gutter="16">-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="幅度" prop="rangeData">-->
        <!--              <a-input placeholder="请输入" v-model="model.rangeData" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--        </a-row>-->
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import JEditor from '@/components/jeecg/JEditor'
import JSwitch from '@/components/jeecg/JSwitch'

import moment from 'moment'
import { getShiftSystem, productTypeSpoolingList, productTypeSpunYarn } from '../../../../api/customApi'
export default {
  name: 'TuiCuShaModal',
  components: {
    JEditor,
    JSwitch
  },
  props: {
    planTime: String
  },
  data() {
    return {
      title: '操作',
      visible: false,
      time: null,
      workHours: null,
      machineHours: null,
      disable: true,
      model: {
        planTime: '',
        workshop: null,
        shift: null,
        workHours: '',
        machineHours: '',
        deviceNo: '',
        deviceId: '',
        workNo: '',
        realname: '',
        machineClassification: '',
        model: '',
        productCategory: '',
        company: '',
        startTime: '',
        endTime: '',
        productType: null,
        productBranch: '',
        machineCoefficient: '',
        productTypeCoefficient: '',
        unitPriceCoefficient: '',
        comprehensiveCoefficient: '',
        ingots: '',
        fixedOutputEightHours: '',
        machinesNum: '',
        machinesNumEightHours: '',
        fixedMachinesNum: '',
        totalMachinesRate: '',
        takeoverLength: '',
        handoverLength: '',
        realityLength: '',
        weight: '',
        doffNum: '',
        machinesOutput: '',
        wagesOutput: '',
        expansionMachines: '',
        changeTubeBoxNum: '',
        changeTubeBoxNumEightHours: '',
        outputPrice: '',
        changeTubeBoxPrice: '',
        changeTubeBoxWages: '',
        outputWages: '',
        ingotsNumSubsidies: '',
        coefficientDeduction: '',
        otherSubsidies: '',
        totalWages: '',
        completionRate: '',
        machinesMaintenance: '',
        remark: '',
        selfSpoolingFixedMachinesRate: '',
        workingTime: '',
        manageMachines: '',
        machinesCarTime: '',
        machinesCarDayTime: '',
        workIdConversion: '',
        originalPrice: '',
        originalWages: '',
        originalNow: '',
        rangeData: '',
        secondDrawing: '',
        preDrawing: '',
        fixedLengthDrawing: '',
        preDrawingFeedCount: '',
        preDrawingBucketDropCount: '',
        headDrawingFeedCount: '',
        secondDrawingFeedCount: '',
        secondDrawingBucketDropCount: '',
        secondDrawingCleanLength: '',
        finalDrawingBucketDropCount: '',
        feedUnitPrice: '',
        bucketDropUnitPrice: '',
        cleanInspectionUnitPrice: '',
        preDrawingFeedWages: '',
        headDrawingFeedWages: '',
        secondDrawingFeedWages: '',
        secondDrawingBucketDropWages: '',
        secondDrawingCleanWages: '',
        finalDrawingBucketDropWages: '',
        finalDrawingCleanWages: '',
        singlePlatformViewingRate: '',
        platformReview: '',
        quantify: '',
        linearVelocity: '',
        fixedLengthRove: '',
        fixedLengthEightHours: '',
        bucketChangeNum: '',
        doffUnitPrice: '',
        bucketChangeUnitPrice: '',
        cleanProductionUnitPrice: '',
        doffWages: '',
        bucketChangeWages: '',
        cleanProductionWages: '',
        platformDayHours: ''
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      url: {
        add: '/crm_salary_excel_rove/crmSalaryExcelRove/add',
        edit: '/crm_salary_excel_rove/crmSalaryExcelRove/edit'
      }
    }
  },
  created() {},
  methods: {
    changeWorkHours(date, dateString) {
      this.model.workHours = dateString + ' 00:00:00'
      // this.model.workHours = new Date(dateString).getTime()
    },
    changeMachineHours(date, dateString) {
      this.model.machineHours = dateString + ' 00:00:00'
      // this.model.machineHours = new Date(dateString).getTime()
    },
    changeProductType(val) {
      productTypeSpoolingList({ id: val }).then(res => {
        // this.model = res.result.records[0]
        this.model.productCategory = res.result.records[0].productCategory
        this.model.productBranch = res.result.records[0].productBranch
        this.model.machineCoefficient = res.result.records[0].machineCoefficient
        this.model.productTypeCoefficient = res.result.records[0].productTypeCoefficient
        this.model.unitPriceCoefficient = res.result.records[0].unitPriceCoefficient
        this.model.ingots = res.result.records[0].ingots
        this.model.fixedMachinesNum = res.result.records[0].fixedMachinesNum
        this.model.outputPrice = res.result.records[0].outputPrice
        this.model.changeTubeBoxPrice = res.result.records[0].changeTubeBoxPrice
        this.model.originalPrice = res.result.records[0].originalPrice
      })
    },
    changeTime(date, dateString) {
      this.model.planTime = dateString
    },
    add() {
      this.disable = false
      this.model.planTime = this.planTime
      this.time = this.planTime
      this.edit({}, 1)
    },
    edit(record, isEdit) {
      if (isEdit != 1) {
        this.model = Object.assign({}, record)
        this.time = moment(this.model.planTime)
      }

      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.disable = true
      this.$refs.form.resetFields()
      this.model.planTime = ''
      this.model.workshop = null
      this.model.shift = null
      this.model.workHours = ''
      this.model.machineHours = ''
      this.model.deviceNo = ''
      this.model.deviceId = ''
      this.model.workNo = ''
      this.model.realname = ''
      this.model.machineClassification = ''
      this.model.model = ''
      this.model.productCategory = ''
      this.model.productType = null
      this.model.productBranch = ''
      this.model.machineCoefficient = ''
      this.model.productTypeCoefficient = ''
      this.model.unitPriceCoefficient = ''
      this.model.comprehensiveCoefficient = ''
      this.model.ingots = ''
      this.model.fixedOutputEightHours = ''
      this.model.machinesNum = ''
      this.model.machinesNumEightHours = ''
      this.model.fixedMachinesNum = ''
      this.model.totalMachinesRate = ''
      this.model.takeoverLength = ''
      this.model.handoverLength = ''
      this.model.realityLength = ''
      this.model.weight = ''
      this.model.doffNum = ''
      this.model.machinesOutput = ''
      this.model.wagesOutput = ''
      this.model.expansionMachines = ''
      this.model.changeTubeBoxNum = ''
      this.model.changeTubeBoxNumEightHours = ''
      this.model.outputPrice = ''
      this.model.changeTubeBoxPrice = ''
      this.model.changeTubeBoxWages = ''
      this.model.outputWages = ''
      this.model.ingotsNumSubsidies = ''
      this.model.coefficientDeduction = ''
      this.model.otherSubsidies = ''
      this.model.totalWages = ''
      this.model.completionRate = ''
      this.model.machinesMaintenance = ''
      this.model.remark = ''
      this.model.platformReview = ''
      this.model.singlePlatformViewingRate = ''
      this.model.platformDayHours = ''
      this.model.company = ''
      this.model.startTime = ''
      this.model.endTime = ''
      this.model.selfSpoolingFixedMachinesRate = ''
      this.model.workingTime = ''
      this.model.manageMachines = ''
      this.model.machinesCarTime = ''
      this.model.machinesCarDayTime = ''
      this.model.workIdConversion = ''
      this.model.originalPrice = ''
      this.model.originalWages = ''
      this.model.originalNow = ''
      this.model.rangeData = ''
      this.model.quantify = ''
      this.model.linearVelocity = ''
      this.model.fixedLengthRove = ''
      this.model.fixedLengthEightHours = ''
      this.model.bucketChangeNum = ''
      this.model.bucketChangeUnitPrice = ''
      this.model.doffUnitPrice = ''
      this.model.cleanProductionUnitPrice = ''
      this.model.doffWages = ''
      this.model.bucketChangeWages = ''
      this.model.cleanProductionWages = ''
    },

    handleOk() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model)
          console.log('formData', formData)
          //时间格式化
          httpAction(httpurl, formData, method)
            .then(res => {
              if (res.success) {
                this.$message.success(res.message != null ? res.message : '执行成功')
                this.$emit('ok')
              } else {
                this.$message.warning(res.message != null ? res.message : '执行失败')
              }
            })
            .finally(() => {
              this.confirmLoading = false
              this.close()
            })
        } else {
          return false
        }
      })
    },

    handleCancel() {
      this.close()
    }
  }
}
</script>

<style scoped></style>
